﻿package idv.cjcat.monica.platformer.player {
	import idv.cjcat.rusher.engine.logger.LogType;
	import idv.cjcat.rusher.geom.Vec2D;
	
	internal class FallingDownState extends PlayerState {
		
		public function FallingDownState(controller:PlayerController, direction:Number) {
			super(controller, direction);
			controller.engine.logger.log("Entered state: FallingDownState", LogType.INFO, controller);
		}
		
		override public function startJump():void {
			if (controller.jumpCount < PlayerController.MAX_JUMPS) {
				setState(JumpingUpState);
				setPlayerMovieClip(renderTarget.jumpingUpRoll, true);
			}
		}
		
		override public function onTick(time:Number):void {
			if (controller.onFloor) {
				if (controller.moving) {
					if (controller.dashing) {
						setState(RunningState);
						setPlayerMovieClip(renderTarget.running, true);
					} else {
						setState(WalkingState);
						setPlayerMovieClip(renderTarget.moving, true);
					}
				} else {
					setState(StandingState);
					setPlayerMovieClip(renderTarget.landing, false);
				}
				return;
			}
			
			var vel:Vec2D = getVelocity();
			if (controller.moving) {
				if (controller.onWall && (controller.direction == controller.wallingDirection)) {
					setState(WallingState);
					setPlayerMovieClip(renderTarget.walling, true);
				} else {
					vel.x = controller.direction * PlayerController.WALKING_SPEED;
				}
			} else {
				vel.x = 0;
			}
			setVelocity(vel);
		}
	}
}